
import "../css/animate.min.css"
import "../css/about.css"
//WOW引入
import { WOW } from "../js/wow.js";
//整合首页用到的所有js
import {
    getIndexAbout
} from "./request.js";

let imgs = document.querySelectorAll("img")
let banner = document.querySelectorAll(".banner>img")
let stop = document.querySelector(".video")
let play = document.querySelector(".play")
let playText = document.querySelector(".playText")
let video = document.querySelectorAll(".video>img")
let headPhoto = document.querySelectorAll("ol>li>img")
console.log(headPhoto);

//图片添加类名进行懒加载
imgs.forEach(item => {
    item.classList.add("lazy-img")
})

import {
    lazyLoad
} from "../utils/lazyLoad.js";
window.onload = async function () {
    let resAbout = await getIndexAbout();
    let res = resAbout.results
    let address = [];
    //拿到每个图片的地址
    res.forEach((item)=>{
        address.push(item.photo_detail.url)
    })
    //将每张图片地址给到每个img
    imgs.forEach((item,index)=>{
        item.setAttribute("data-src",address[index])
    })


    //懒加载
    lazyLoad(".lazy-img");
};

//给首图文字设置动画
banner.forEach((item,index)=>{
    if(index>0){
        item.classList.add("animated")
        item.classList.add("flipInX")
    }
})

//设置宣传页面动画
play.addEventListener("mouseover",()=>{
    play.classList.add("animated")
    play.classList.add("pulse")
    play.classList.add("infinite")
    playText.classList.add("animated")
    playText.classList.add("pulse")
    playText.classList.add("infinite")
})
play.addEventListener("mouseout",()=>{
    play.classList.remove("animated")
    playText.classList.remove("animated")
})
let flag = false
stop.addEventListener("click",()=>{
    flag = !flag
    if(flag){
        video.forEach((item,index)=>{
            if(index>0){
                item.style.opacity = 0
            }
        })
    }else{
        play.style.opacity = 1;
        playText.style.opacity = 1;
    }
})

//设置人物介绍动画
headPhoto.forEach(item=>{
    item.classList.add("animated")
    item.classList.add("wobble")
    item.classList.add("infinite")
})
//wow
new WOW().init()